package com.gxuwz.attend.web.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet(name = "logoutServlet",urlPatterns = "/logout")
public class LogoutServlet extends HttpServlet {
    private final static String VIEW_LOGIN="login.jsp";
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取当前用户的会话对象
        HttpSession session = req.getSession(false);
        if (session != null) {
            System.out.println("session:"+session);
            // 清除当前用户的会话数据
            session.invalidate();
        }
        // 重定向到登录页面
        resp.sendRedirect(VIEW_LOGIN);
    }
}
